package com.simple.space.runner;

import com.simple.space.config.global.GlobalConfig;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;

/**
 * <p>
 *     <br/>启动前置操作类
 * </p>
 */
public class StartRunner implements CommandLineRunner{

    private static Logger LOG = LoggerFactory.getLogger(StartRunner.class);

    @Autowired
    private GlobalConfig globalConfig;

    //@Resource(name = Constant.DICTIONARY_CACHE_KEY)
    //private DictionariesCache dictionariesCache;

    @Override
    public void run(String... strings) throws Exception {
        /*try {
            LOG.info("Micro Service start.");
            initCache();
            validationDb();
        } catch (BusinessException e) {
            LOG.error(e.getMessage());
            System.exit(-1);
        }*/
        LOG.info("字典缓存未完成");

    }

    private void initCache() {
        LOG.debug("字典数据缓存");
        //Object dicMap = dictionariesCache.get("home");
        //LOG.debug("字典缓存数据：" + JsonUtil.toString(dicMap));
    }

    private void validationDb() {
        /*if(!globalConfig.isValidationDb()) {
            return ;
        }
        LOG.debug("数据库连接验证");
        try {
            DataSource dataSource = SpringContextUtil.getBean("masterDataSource");
            dataSource.getConnection();
        } catch (SQLException e) {
            throw new BusinessException(ErrorCode.DB_SERVER_CONNECT, ErrorCode.DB_SERVER_CONNECT.getMessage());
        }*/
    }
}
